package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.shuati.domain.ShuatiChapter;
import com.ruoyi.shuati.service.IShuatiChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 章节Controller
 *
 * @author ruoyi
 * @date 2024-06-17
 */
@RestController
@RequestMapping("/shuati/chapter")
public class ShuatiChapterMobileController extends BaseController
{
    @Autowired
    private IShuatiChapterService shuatiChapterService;

    /**
     * 查询章节列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ShuatiChapter shuatiChapter)
    {
        startPage();
        List<ShuatiChapter> list = shuatiChapterService.selectShuatiChapterList(shuatiChapter);
        return getDataTable(list);
    }


    /**
     * 获取章节详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:chapter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shuatiChapterService.selectShuatiChapterById(id));
    }

    /**
     * 新增章节
     */
    @PostMapping
    public AjaxResult add(@RequestBody ShuatiChapter shuatiChapter)
    {
        return toAjax(shuatiChapterService.insertShuatiChapter(shuatiChapter));
    }

    /**
     * 修改章节
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ShuatiChapter shuatiChapter)
    {
        return toAjax(shuatiChapterService.updateShuatiChapter(shuatiChapter));
    }

    /**
     * 删除章节
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shuatiChapterService.deleteShuatiChapterByIds(ids));
    }
}
